package searchPractice;

public class binarySearch {
    public static void main(String[] args){
        int[] arr = {7, 23, 79, 81, 103, 127, 131, 147};

        System.out.println(Func(arr,148));
    }

    public static int Func(int[] arr, int num){
        int left = 0;
        int right = arr.length - 1;
        int mid = (left + right) / 2;
        while(left <= right){
            if(arr[mid] < num){
                left = mid + 1;
                mid = (left + right) / 2;
            }else if(arr[mid] > num){
                right = mid - 1;
                mid = (left + right) / 2;
            }else {
                return mid;
            }
        }
        return -1;
    }
}
